/*
卖酒服务器适配器类

将接口返回的服务器信息格式化成可以直接用于实例化SellingServer、SessionSellingServer的数据
 */
import DataAdapter from "./dataAdapter"

export default class SellingServerAdapter extends DataAdapter
{
    /**
     * 接口返回的数据转换为可以直接用于实例化SellingServer的数据
     *
     * 该方法同样适用于SessionSellingServer类
     * @param {{}} rawData 接口返回的单个服务器信息的数据，参见`_requestServer()`和`_requestAccessibleServers()`的用法
     * @returns {{vCardData: {avatarUri: (string|*), career: (string|*), address: (string|*), gender: (string|*|number), contactEmail: (string|*), jobTitle: (string|*), genderId: (number|*), shopName: (string|*), birthYear: (number|*), keepSecret: (boolean|*), name: *, id: *, contactPhone: (string|*), introduction: (string|*), age: (number|*)}, vCardId: (number|*), salesmanId: (number|{vCardId: number}|*|Number), agentId: (*|Number), showName: (string|*|store.data.agent.showName), isConfirmed: (boolean|*), lastServerData: {}, agentData: {showName: (string|*|store.data.agent.showName), customerRegistrationClosed: (boolean|*), name: *, goodsPriceHidden: (boolean|*), id: *, sn: (string|store.data.agent.sn|applicate.data.consultant_sn|bindFunction.data.consultant_sn|*), logoUri: (string|store.data.agent.logoUri), emptyShopCartBgUri: *, isWholesale: (boolean|*)}, isServiceable: (boolean|*)}}
     */
    static convert(rawData){
        let agentData = rawData.agent, vCardData = rawData.vCard,
            salesControl = rawData.salesControl, customImages = rawData.customImages;
        if(typeof customImages.emptyShopCartBgUri === 'undefined'){
            customImages.emptyShopCartBgUri = customImages.emptyShoppingCart
        }
        return {
            showName: rawData.showName,
            salesmanId: rawData.salesmanId,
            agentId: rawData.agentId,
            vCardId: rawData.vCardId,
            isConfirmed: rawData.isConfirmed,
            isServiceable: rawData.isServiceable,
            lastServerData: {},
            agentData:{
                ...agentData,
                ...salesControl,
                ...customImages,
                
            },
            vCardData : {
                ...vCardData
            }
        }
    }
}